<?php

/**
 * NOTICE OF LICENSE
 *
 * THIS SOURCE FILE IS PART OF EVEBIT'S PRIVATE PROJECT.
 * 
 * DO NOT USE THIS FILE IN OTHER PLACE.
 *
 * @category    EveBit_Library
 * @package     Application
 * @author      Cheng Wei <berlios.o@gmail.com>
 * @version     $$Id: Bootstrap.php 518 2011-04-25 05:12:29Z chen.gan $$
 * @copyright   Copyright (c) 2008 Evebit Inc. China (http://www.evebit.com)
 */

/**
 * Bootstrap for module
 * 
 * It try to find configure file in modules 'configs' folder.
 * File name should be [scope].ini, like 'frontend.ini' and 'backend.ini'.
 * Then it parse the routes tables.
 * Then merge them into front controller.
 * 
 * For example:
 * <code>
 * [production]
 * routes.default_index_event.route 	= "([-_ a-zA-Z0-9]+)/?(\w+)?"
 * routes.default_index_event.type 	= Zend_Controller_Router_Route_Regex
 * routes.default_index_event.defaults.module = default
 * routes.default_index_event.defaults.controller = index
 * routes.default_index_event.defaults.action = locale
 * routes.default_index_event.map.1 = name
 * routes.default_index_event.map.2 = lang
 * </code>
 * 
 * @docinfo
 * 
 * @category    EveBit_Library
 * @package     Application
 * @author      Cheng Wei <berlios.o@gmail.com>
 * @version     $$Id: Bootstrap.php 518 2011-04-25 05:12:29Z chen.gan $$
 */
class Evebit_Application_Module_Bootstrap extends Zend_Application_Module_Bootstrap {

	/**
	 * Init routes for this module
	 */
	protected function _initRoutes() {
		
		$frontController = $this->getApplication()->getResource('frontController');
		
		$file = $this->getApplication()->getApplication()->getScope();
		$configFileLocation = APPLICATION_PATH . '/modules/' . strtolower($this->getModuleName()) .
			 "/configs/$file.ini";
			
			if (file_exists($configFileLocation)) {
				$config = new Zend_Config_Ini($configFileLocation, 'production');
				if ($config->routes) {
					$router = new Zend_Controller_Router_Rewrite();
					$router->addConfig($config, 'routes');
					$frontController->getRouter()->addRoutes($router->getRoutes());
				
				}
			}
		}
	}
